package com.ruoyi.lock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lock.domain.AUnit;
import com.ruoyi.lock.service.IAUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 单元管理Controller
 * 
 * @author arvin
 * @date 2025-03-01
 */
@RestController
@RequestMapping("/lock/unit")
public class AUnitController extends BaseController
{
    @Autowired
    private IAUnitService aUnitService;

    /**
     * 查询单元管理列表
     */
    @PreAuthorize("@ss.hasPermi('lock:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(AUnit aUnit)
    {
        startPage();
        List<AUnit> list = aUnitService.selectAUnitList(aUnit);
        return getDataTable(list);
    }

    /**
     * 查询单元管理列表（不分页）
     */
    @PreAuthorize("@ss.hasPermi('lock:unit:list')")
    @GetMapping("/list2")
    public TableDataInfo list2(AUnit aUnit)
    {
        List<AUnit> list = aUnitService.selectAUnitList(aUnit);
        return getDataTable(list);
    }

    /**
     * 导出单元管理列表
     */
    @PreAuthorize("@ss.hasPermi('lock:unit:export')")
    @Log(title = "单元管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AUnit aUnit)
    {
        List<AUnit> list = aUnitService.selectAUnitList(aUnit);
        ExcelUtil<AUnit> util = new ExcelUtil<AUnit>(AUnit.class);
        util.exportExcel(response, list, "单元管理数据");
    }

    /**
     * 获取单元管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('lock:unit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aUnitService.selectAUnitById(id));
    }

    /**
     * 新增单元管理
     */
    @PreAuthorize("@ss.hasPermi('lock:unit:add')")
    @Log(title = "单元管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AUnit aUnit)
    {
        return toAjax(aUnitService.insertAUnit(aUnit));
    }

    /**
     * 修改单元管理
     */
    @PreAuthorize("@ss.hasPermi('lock:unit:edit')")
    @Log(title = "单元管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AUnit aUnit)
    {
        return toAjax(aUnitService.updateAUnit(aUnit));
    }

    /**
     * 删除单元管理
     */
    @PreAuthorize("@ss.hasPermi('lock:unit:remove')")
    @Log(title = "单元管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aUnitService.deleteAUnitByIds(ids));
    }
}
